/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.admanager.generalpattern.plugin.generalpattern.impl;

import java.util.Collection;
import org.admanager.generalpattern.plugin.generalpattern.ComponentPort;
import org.admanager.generalpattern.plugin.generalpattern.ConnectorRole;
import org.admanager.generalpattern.plugin.generalpattern.generalpatternPackage;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Component Port</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.admanager.generalpattern.plugin.generalpattern.impl.ComponentPortImpl#getAttachedRole <em>Attached Role</em>}</li>
 *   <li>{@link org.admanager.generalpattern.plugin.generalpattern.impl.ComponentPortImpl#getDelegatedPorts <em>Delegated Ports</em>}</li>
 *   <li>{@link org.admanager.generalpattern.plugin.generalpattern.impl.ComponentPortImpl#isIsInput <em>Is Input</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ComponentPortImpl extends SimpleElementImpl implements ComponentPort {
	/**
	 * The cached value of the '{@link #getAttachedRole() <em>Attached Role</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAttachedRole()
	 * @generated
	 * @ordered
	 */
	protected ConnectorRole attachedRole;

	/**
	 * The cached value of the '{@link #getDelegatedPorts() <em>Delegated Ports</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDelegatedPorts()
	 * @generated
	 * @ordered
	 */
	protected EList delegatedPorts;

	/**
	 * The default value of the '{@link #isIsInput() <em>Is Input</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsInput()
	 * @generated
	 * @ordered
	 */
	protected static final boolean IS_INPUT_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isIsInput() <em>Is Input</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsInput()
	 * @generated
	 * @ordered
	 */
	protected boolean isInput = IS_INPUT_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComponentPortImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return generalpatternPackage.Literals.COMPONENT_PORT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ConnectorRole getAttachedRole() {
		if (attachedRole != null && attachedRole.eIsProxy()) {
			InternalEObject oldAttachedRole = (InternalEObject)attachedRole;
			attachedRole = (ConnectorRole)eResolveProxy(oldAttachedRole);
			if (attachedRole != oldAttachedRole) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, generalpatternPackage.COMPONENT_PORT__ATTACHED_ROLE, oldAttachedRole, attachedRole));
			}
		}
		return attachedRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ConnectorRole basicGetAttachedRole() {
		return attachedRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAttachedRole(ConnectorRole newAttachedRole) {
		ConnectorRole oldAttachedRole = attachedRole;
		attachedRole = newAttachedRole;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, generalpatternPackage.COMPONENT_PORT__ATTACHED_ROLE, oldAttachedRole, attachedRole));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getDelegatedPorts() {
		if (delegatedPorts == null) {
			delegatedPorts = new EObjectResolvingEList(ComponentPort.class, this, generalpatternPackage.COMPONENT_PORT__DELEGATED_PORTS);
		}
		return delegatedPorts;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isIsInput() {
		return isInput;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIsInput(boolean newIsInput) {
		boolean oldIsInput = isInput;
		isInput = newIsInput;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, generalpatternPackage.COMPONENT_PORT__IS_INPUT, oldIsInput, isInput));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case generalpatternPackage.COMPONENT_PORT__ATTACHED_ROLE:
				if (resolve) return getAttachedRole();
				return basicGetAttachedRole();
			case generalpatternPackage.COMPONENT_PORT__DELEGATED_PORTS:
				return getDelegatedPorts();
			case generalpatternPackage.COMPONENT_PORT__IS_INPUT:
				return isIsInput() ? Boolean.TRUE : Boolean.FALSE;
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case generalpatternPackage.COMPONENT_PORT__ATTACHED_ROLE:
				setAttachedRole((ConnectorRole)newValue);
				return;
			case generalpatternPackage.COMPONENT_PORT__DELEGATED_PORTS:
				getDelegatedPorts().clear();
				getDelegatedPorts().addAll((Collection)newValue);
				return;
			case generalpatternPackage.COMPONENT_PORT__IS_INPUT:
				setIsInput(((Boolean)newValue).booleanValue());
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
			case generalpatternPackage.COMPONENT_PORT__ATTACHED_ROLE:
				setAttachedRole((ConnectorRole)null);
				return;
			case generalpatternPackage.COMPONENT_PORT__DELEGATED_PORTS:
				getDelegatedPorts().clear();
				return;
			case generalpatternPackage.COMPONENT_PORT__IS_INPUT:
				setIsInput(IS_INPUT_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case generalpatternPackage.COMPONENT_PORT__ATTACHED_ROLE:
				return attachedRole != null;
			case generalpatternPackage.COMPONENT_PORT__DELEGATED_PORTS:
				return delegatedPorts != null && !delegatedPorts.isEmpty();
			case generalpatternPackage.COMPONENT_PORT__IS_INPUT:
				return isInput != IS_INPUT_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (isInput: ");
		result.append(isInput);
		result.append(')');
		return result.toString();
	}

} //ComponentPortImpl
